﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TravelAgencyDAL;

namespace TravelAgencyAspNet.Agents
{
    /// <summary>
    /// Summary description for DisplayTripPhoto
    /// </summary>
    public class DisplayTripPhoto : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            TravelAgencyDAO dao = new TravelAgencyDAO();

            int photoId = Int32.Parse(context.Request.QueryString["photoId"]);
            using (dao)
            {
                Photo photo = dao.GetPhotoByPhotoId(photoId);

                if (photo != null)
                {
                    context.Response.ContentType = "image/png";
                    context.Response.OutputStream.Write(photo.PhotoContent, 0, photo.PhotoContent.Length);
                }
            }     
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}